﻿layui.use(['form', 'http', 'popup'], function () {
    var form = layui.form;
    var $ = layui.$;
    var http = layui.http;
    var popup = layui.popup;

    form.on('submit(submitBtn)', function (data) {
        var loading = layer.load(2);
        http.ajax({
            url: '/Bookshelf/AddOrUpdate',
            data: data.field,
            success: function (res) {
                layer.close(loading);
                if (res.code === 0) {
                    popup.success(res.msg, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.table.reload("dataTable");
                    });
                } else {
                    popup.failure(res.msg);
                }
            },
            error: function () {
                layer.close(loading);
                popup.failure("请求失败，请稍后重试");
            }
        });
        return false;
    })
    window.save = function () {
        $("#submit").trigger('click');
    }
});